package whisper.service.controller;


import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;
import whisper.common.exception.check.EmptyFileException;
import whisper.common.support.response.WebResponse;
import whisper.common.support.response.WebResponseCode;
import whisper.service.service.MediaService;

import java.io.IOException;


/**
 * Created by JT on 2017/11/2.
 */
@RestController
@RequestMapping("/whisper/media")
public class MediaController {

    @Autowired
    private MediaService mediaService;

    @PostMapping("/upload")
    public WebResponse upload(@RequestParam("file") MultipartFile file) throws IOException {
        if (file.isEmpty())
            throw new EmptyFileException(WebResponseCode.CODE_ERROR, "文件未上传！");
        mediaService.receiveFile(file);
        return new WebResponse().ok("文件上传成功！");
    }

}
